package com.yycx.msg.provider.controller;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.security.OpenHelper;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.yycx.common.mybatis.model.*;

import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RestController;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.msg.client.entity.MsgReceive;
import com.yycx.msg.provider.service.MsgReceiveService;


/**
 * 消息接收表控制器
 *
 * @author flyme
 * @date 2020-02-28
 */
@Api(tags = "消息通知")
@RestController
@RequestMapping("/msg/receive/")
public class MsgReceiveController extends BaseController<MsgReceiveService, MsgReceive> {

    @ApiOperation(value = "消息接收表-分页列表", notes = "消息接收表分页列表")
    @RequestMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "消息接收表-列表", notes = "消息接收表列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "消息接收表-添加", notes = "添加消息接收表")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "消息接收表-更新", notes = "更新消息接收表")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "消息接收表-删除", notes = "删除消息接收表")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "消息接收表-详情", notes = "消息接收表详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }


    @ApiOperation(value = "消息接收表-全部未读消息", notes = "全部未读消息")
    @GetMapping(value = "getAllNoReadMessageNum")
    public ResultBody getAllNoReadMessageNum() {
        Long userId = OpenHelper.getUserId();
        return bizService.getAllNoReadMessageNum(userId);
    }

    @ApiOperation(value = "更新消息表", notes = "更新消息表")
    @PostMapping(value = "setReadState")
    public ResultBody setReadState(@RequestParam(required = false) Map map) {
        return bizService.setState(map, "readState", CommonConstants.ENABLED);
    }

    @ApiOperation(value = "一键已读", notes = "一键已读")
    @PostMapping(value = "updateAllReadState")
    public ResultBody updateAllReadState() {
        bizService.updateAllReadState();
        return ResultBody.ok("操作成功");
    }

    @ApiOperation(value = "删除消息", notes = "删除消息")
    @PostMapping(value = "delete")
    public ResultBody setDeleted(@RequestParam(required = false) Map map) {
        return bizService.setState(map, "deleted", CommonConstants.DEL_YES);
    }

    @ApiOperation(value = "后台首页未读消息", notes = "后台首页未读消息")
    @GetMapping(value = "getNoticeList")
    public ResultBody getNoticeList() {
        List<EntityMap> list = bizService.getNoticeList();
        return ResultBody.ok(list);
    }

    @ApiOperation(value = "清空已读", notes = "清空已读")
    @PostMapping(value = "deleteAllRead")
    public ResultBody deleteAllRead() {
        bizService.deleteAllRead();
        return ResultBody.ok("操作成功");
    }

}
